Skip to content

fix(history): never write .agent_history into the project tree - #439

Open
openjiuwen-sync-bot[bot] wants to merge 1 commit into
openJiuwen-ai:mainfrom
openjiuwenai:sync/pr-2263
Open

fix(history): never write .agent_history into the project tree#439
openjiuwen-sync-bot[bot] wants to merge 1 commit into
openJiuwen-ai:mainfrom
openjiuwenai:sync/pr-2263

Conversation

@openjiuwen-sync-bot

@openjiuwen-sync-bot openjiuwen-sync-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Paired: GitHub #439GitCode !2263

Summary

Fixes #​1490: .agent_history was written into the user's project directory when no agent workspace was configured, polluting their execution environment.

Root cause

_build_history_path in four tools used:

base_dir = get_workspace() or str(pathlib.Path(get_cwd()).expanduser().resolve())

When get_workspace() returns None (agent without a workspace), history files landed in the project CWD — i.e. inside the user's project tree.

Change

  • openjiuwen/core/sys_operation/cwd.py: new get_agent_history_base_dir() — prefers the agent workspace; when none is configured, falls back to ~/.openjiuwen/agent_history instead of the CWD.
  • openjiuwen/harness/tools/filesystem.py (write_file + edit_file), shell/bash/_tool.py, shell/powershell/_tool.py: all four _build_history_path call sites now use the helper.

Tests

  • New tests/unit_tests/core/sys_operation/test_cwd.py:
    • workspace set → used as base dir
    • workspace unset → user-level ~/.openjiuwen/agent_history, and not the project CWD

Verification

  • Windows (Python 3.12 + uv): uv run pytest tests/unit_tests/core/sys_operation/test_cwd.py2 passed
  • Linux (Docker, python:3.12-slim + uv): same — 2 passed
  • Existing _build_history_path tests (bash/powershell/filesystem) still pass; the unrelated test_timeout_returns_collected_output failure on Windows is pre-existing (the environment lacks GNU sleep, so echo partial; sleep 5 returns immediately with exit 0) and is not touched by this PR.

Linked Closing Issues:

_build_history_path fell back to the project CWD when no agent workspace
was configured, so tool history (.agent_history/*.json) was written into
the user's project directory, polluting their execution environment
(#1490).

Add get_agent_history_base_dir() in cwd.py: prefers the agent workspace;
when none is configured, falls back to ~/.openjiuwen/agent_history
instead of the CWD. All four _build_history_path call sites (write_file,
edit_file, bash, powershell) now use it.

Closes #1490.

Co-Authored-By: AtomCode (deepseek-v4-flash) <noreply@atomgit.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@openjiuwen-collaboration-bot

Copy link
Copy Markdown

head_sha: 7a7a93105bcc8d9499656318f747d153733e33f1

变更摘要

此 PR 修复了 #​1490 问题:当 agent 未配置 workspace 时,.agent_history 历史文件会被写入用户的项目工作目录(CWD),污染项目树。核心方案是在 cwd.py 中新增 get_agent_history_base_dir() 辅助函数,优先使用 agent workspace,未配置时回退到用户级目录 ~/.openjiuwen/agent_history,并将四个工具中的 _build_history_path 方法统一改为调用该函数。

主要改动

  • 新增 get_agent_history_base_dir() 函数:在 openjiuwen/core/sys_operation/cwd.py 中新增该函数,当 get_workspace() 有值时返回 workspace 路径,否则回退到 ~/.openjiuwen/agent_history,确保历史文件不再落入项目 CWD。
  • filesystem.pyWriteFileToolEditFileTool_build_history_path 重构:将原来的 get_workspace() or str(pathlib.Path(get_cwd())...) 回退逻辑替换为调用 get_agent_history_base_dir(),并更新了 import。
  • bash/_tool.pypowershell/_tool.py_build_history_path 重构:同样移除了对 get_cwd/get_workspace 的直接依赖,改为集中通过 get_agent_history_base_dir() 获取基础目录。
  • 新增单元测试 test_cwd.py:覆盖两种场景——workspace 已设置时返回 workspace 路径;workspace 未设置时返回用户级目录且明确断言不会使用项目 CWD。

@openjiuwen-collaboration-bot

Copy link
Copy Markdown

head_sha: 7a7a93105bcc8d9499656318f747d153733e33f1

代码审查

✅ 未发现问题

@openjiuwen-collaboration-bot

Copy link
Copy Markdown

head_sha: 7a7a93105bcc8d9499656318f747d153733e33f1

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ✅SUCCESS 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A

@openjiuwen-collaboration-bot

Copy link
Copy Markdown

head_sha: 7a7a93105bcc8d9499656318f747d153733e33f1

任务名称 结果 日志操作
静态检查 ✅SUCCESS 点此跳转
防投毒检查 ✅SUCCESS 点此跳转
开源合规检查 ✅SUCCESS 点此跳转
UT测试 ✅SUCCESS 点此跳转
ST测试 N/A N/A
build 编译包 N/A N/A
ruff codecheck ✅SUCCESS N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants